<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="sl" tagdir="/WEB-INF/tags" %>
<%@page import="com.solution.common.config.PublicConfig"%>
<%@page import="com.solution.admin.home.constants.IndexConstants"%>
<%
	String basePath = PublicConfig.ROOT_PATH;
	String imgRootURL = PublicConfig.IMG_ROOT_URL;
	String ossImgZoomWX = PublicConfig.OSS_IMG_ZOOM_WX; //微信图片缩放
%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>订单</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/style.css">
<script src="<%=basePath%>/statics_wx/js/jquery.min.js"></script>
<script src="<%=basePath%>/statics_wx/js/js.js"></script>
<script type="text/javascript" src="<%=basePath%>/statics_wx/js/custom.js"></script>
<script type="text/javascript" src="<%=basePath%>/statics/plugins/layer/layer.js"></script>
<script type="text/javascript">
	//系统域名 
	var rootPath = '<%=basePath%>';
	// 系统上传文件展示域名
	var imgRootURL = '<%=imgRootURL%>';
	
	$(function(){
		function initOrderOperation(){
			// 通过
			$("a[id='btn_approve']").each(function(){
				$(this).click(function(){
					var order_code = $(this).parent().find("#order_code").val();
					$.ajax({
						type : "post",
						url : rootPath + "/wx/sworder/approveOrder",
						data : {
							orderCode : order_code,
							approveResult : '01'
						},
						datatype : "json",
						success : function(json) {
							if(json && json.resultCode == 1){
								layer.msg('订单审核成功',{time:1000});
								// 跳转订单列表页面
								setTimeout(function(){
									window.location.href = rootPath+"/wx/sworder/list";
								},1000);
							}else{
								layer.msg('订单审核失败',{time:1000});
							}
						},
						error : function() {
							layer.msg('订单审核失败',{time:1000});
						}
					});
				});
			});
			// 转驳回订单
			$("a[id='btn_reject']").each(function(){
				$(this).click(function(){
					var order_code = $(this).parent().find("#order_code").val();
					window.location.href = rootPath +"/wx/sworder/toApproveOrder?orderCode="+order_code;
				});
			});
			
			// 查询订单详情
			$("div[name='order_info']").each(function(){
				$(this).click(function(){
					var order_code = $(this).find("#order_code").val();
					var url = rootPath +"/wx/sworder/detail";
					var form = $('<form></form>');  
					form.attr('action', url);  
					form.attr('method', 'post');
					form.attr('target', '_self');
					form.append("<input type='hidden' name='orderCode'  value='"+order_code+"'/>");
					form.appendTo("body");
					form.submit();
				});
			});
			
			// 查看详情清单
			$("div[name='product_info']").each(function(){
				$(this).click(function(){
					var order_code = $(this).parent().find("div:eq(0)").find("#order_code").val();
					var url = rootPath +"/wx/sworder/detail";//detailProductList
					var form = $('<form></form>');  
					form.attr('action', url);  
					form.attr('method', 'post');
					form.attr('target', '_self');
					form.append("<input type='hidden' name='orderCode'  value='"+order_code+"'/>");
					form.appendTo("body");
					form.submit();
				});
			});
		}
		
		// 页面加载绑定事件
		initOrderOperation();
		
		// 上拉加载更多(订单查询分页)
		$(window).on('scroll',function(){
		    if($(window).scrollTop()>=$(document).height()-$(window).height()){
		    	
		    	var page_count = $("#sync_page_count").val();
		    	var current_page = $("#sync_page_num").val();
		    	if(current_page >= page_count){
		    		//layer.msg('已经到底了',{time:500});
		    		return false;
		    	}
		      	var params = "requestType=sync";
		    	$("input[id^='sync_']").each(function(){
		    		if($(this).attr("pname") == "pageNum"){
		    			params = params + "&"+$(this).attr("pname")+"="+(parseInt($(this).val())+1);
		    		}else{
		    			params = params + "&"+$(this).attr("pname")+"="+$(this).val();
		    		}
		      	});
				var url = rootPath + "/wx/sworder/list";
				$.ajax({
					type : "post",
					url : url,
					data : params,
					datatype : "json",
					success : function(jsonObject) {
						var json = $.parseJSON(jsonObject);
						$("#sync_page_num").val(json.currentPage);
						if(json.recordList){
							for(var i = 0 ; i < json.recordList.length; i++){
								var order = json.recordList[i];
								var order_str = "<dt>"+
													 "<div class=\"box6\">"+
														"<div class=\"hd\" name=\"order_info\">"+
															"<strong> <em>订单编号:"+order.orderCode+"</em>"+
															"</strong> <span>"+order.orderStatusName+"</span>"+
															"<input type=\"hidden\"  id=\"order_code\"  value=\""+order.orderCode+"\"/>"+
														"</div>"+
														"<div class=\"bd\" name=\"product_info\">";
															if(order.productList && order.productList.length == 1){
																order_str += "<div class=\"pic_list2\">";
																order_str +=    "<ul>";
																	for(var j = 0; j<order.productList.length; j++){
																		var product = order.productList[j];
																		order_str +="<li>";
																		order_str +="<div class=\"box5\">";
																		order_str +="<div class=\"pic\">";
																		order_str +=	"<img src=\""+imgRootURL+"/"+product.imagePath+"\" />";
																		order_str +="</div>";
																		order_str +="<div class=\"item-info\">";
																		order_str +=	"<h2>"+product.productName+"</h2>";
																		order_str +=	"<h3>";
																		if(product.productSpecList){
																			for(var k = 0; k < product.productSpecList.length; k++){
																				var spec = product.productSpecList[k];
																				order_str +=spec.specName+":"+spec.specValue+"  ";
																			}
																		}
																		order_str +=	"</h3>";
																		order_str +=	"<h4>";
																		order_str +=		"<strong>￥<em>"+numberInteger(product.productPrice)+"</em>"+numberDecimal(product.productPrice);
																		order_str +=		"</strong><b> x "+product.buyNum+"</b>";
																		order_str +=	"</h4>";
																		order_str +="</div>";
																		order_str +="</div>";
																		order_str +="</li>";
																	}
																			
																order_str += "</ul>";
																order_str += "</div>";
															}
															if(order.productList && order.productList.length > 1){
																order_str += "<a href=\"javascript:void(0)\">";
																order_str += 	"<div class=\"piclist1\">";
																order_str += 		"<div class=\"piclist1_con\">";
																order_str += 			"<ul>";
																for(var m = 0; m < order.productList.length; m++){
																	var product = order.productList[m];
																	if(i<4){
																		order_str += 		"<li><img src=\""+imgRootURL+"/"+product.imagePath+"\" /></li>";
																	}
																}
																order_str += 			"</ul>";
																order_str += 		"</div>";
																order_str += 		"<b> <i>共"+order.productList.length+"件</i><em></em>";
																order_str += 		"</b>";
																order_str += 	"</div>";
																order_str += "</a>";
															}
															
										order_str += "</div>";
										order_str += "<div class=\"bottom\">";
										order_str += "	<div class=\"total_order\">";
										order_str += "		<p>";
										order_str += "			<i>共${order.productList.size()}件商品</i> 应付:<b>¥<em>"+numberInteger(order.realPayMoney)+"</em>"+numberDecimal(order.realPayMoney);
										order_str += "		</b><s>(运费¥"+numberRand2(order.deliveryFeeMoney)+")</s>";
										order_str += "		</p>";
										order_str += "	</div>";
										order_str += "	<div class=\"nav_bottom\">";
										order_str += 		"<p>";
										order_str += 			"<input type=\"hidden\"  id=\"order_code\" value=\""+order.orderCode+"\"/>";
										if(order.orderStatus == "02"){
											// 待审核
											order_str += 		"<a id=\"btn_reject\" href=\"javascript:void(0)\" class=\"btn1\">驳回</a>";
											order_str += 		"<a id=\"btn_approve\" href=\"javascript:void(0)\" class=\"btn2\">通过</a>";
										}
										order_str += 		"</p>";
										order_str += "	</div>";
										order_str += "</div>";
										order_str += "</div>";
										order_str += "</dt>";
									$("#order_list").append($(order_str));
							}
						}
						// 重新绑定事件
						initOrderOperation();
					},
					error : function() {
						layer.msg('订单查询失败',{time:1000});
					}
				});
		    }
		})
		
	});
	
	
</script>
</head>
<body style="background:#f5f5f5">
<c:set var="rootPath" value="<%=basePath %>"></c:set>
<c:set var="imgRootURL" value="<%=imgRootURL %>"></c:set>
<c:set var="ossImgZoomWX" value="<%=ossImgZoomWX %>"></c:set>

	<c:forEach items="${hiddenParamMap }" var="item">
		<input type="hidden"  id="sync_${item.key }" pname="${item.key}" value="${item.value}"/>
	</c:forEach>
	<input type="hidden"  id="sync_page_num" pname="pageNum"  value="${pageBean.currentPage }"/>
	<input type="hidden"  id="sync_num_per_page" pname="numPerPage" value="${pageBean.numPerPage}"/>
	<input type="hidden"  id="sync_page_count"  pname="pageCount" value="${pageBean.pageCount }"/>
	
	<div class="order_nav">
		<ul>
			<li ${approveResult == null and orderStatus == null ? "class='current'" : ""}><a href="${rootPath}/wx/sworder/list"><span>全部</span><i></i></a></li>
			<li ${orderStatus == "02" ? "class='current'" : ""}><a href="${rootPath}/wx/sworder/list?orderStatus=02"><span>待审核</span><i></i></a></li>
			<li ${approveResult == "01" ? "class='current'" : ""}><a href="${rootPath}/wx/sworder/list?approveResult=01"><span>审核通过</span><i></i></a></li>
			<li ${orderStatus == "03" ? "class='current'" : ""}><a href="${rootPath}/wx/sworder/list?orderStatus=03"><span>审核驳回</span><i></i></a></li>
		</ul>
	</div>
	<div class="order_list1">
		<dl id="order_list">
			<c:forEach items="${orderList}" var="order">
				<dt>
					<div class="box6">
						<div class="hd" name="order_info">
							<strong> <em>订单编号:${order.orderCode}</em></strong> 
							
							<c:choose>
								<c:when test="${order.approveResult eq '01' }">
									<span>审核通过</span>
								</c:when>
								<c:when test="${order.approveResult eq '02' }">
									<span>审核驳回</span>
								</c:when>
								<c:otherwise>
									<span>${order.orderStatusName}</span>
								</c:otherwise>
							</c:choose>
							<input type="hidden"  id="order_code"  value="${order.orderCode}"/>
						</div>
						<div class="bd" name="product_info">
							<c:if test="${order.productList.size() == 1 }">
								<div class="pic_list2">
									<ul>
											<c:forEach items="${order.productList }" var="product">
												<li>
													<div class="box5">
														<div class="pic">
															<img src="${imgRootURL}/${product.imagePath}${ossImgZoomWX}" />
														</div>
														<div class="item-info">
															<h2>${product.productName}</h2>
															<h3>
																<c:forEach items="${product.productSpecList}" var="spec">
																	${spec.specName}：${spec.specValue}&nbsp;&nbsp;
																</c:forEach>
															</h3>
															<h4>
																<strong>￥<em><sl:nformat num="${order.realPayMoney}" format=".00" type="2"/></em>
													 						  <sl:nformat num="${order.realPayMoney}" format=".00" type="3"/>
																</strong><b>x${product.buyNum}</b>
															</h4>
														</div>
													</div>
												</li>
											</c:forEach>
									</ul>
								</div>
							</c:if>
							
							
							<c:if test="${order.productList.size() > 1 }">
								<a href="#">
									<div class="piclist1">
										<div class="piclist1_con">
											<ul>
												<c:forEach items="${order.productList }" var="product" varStatus="ind">
													<c:if test="${ind.index < 4 }">
														<li><img src="${imgRootURL}/${product.imagePath}${ossImgZoomWX}" /></li>
													</c:if>
												</c:forEach>
											</ul>
										</div>
										<b> <i>共${order.productList.size()}件</i><em></em>
										</b>
									</div>
								</a>
							</c:if>
						</div>
						
						<div class="bottom">
							<div class="total_order">
								<p>
									<i>共${order.productList.size()}件商品</i> 应付:<b>¥<em><sl:nformat num="${order.realPayMoney}" format=".00" type="2"/></em>
													 						  			  <sl:nformat num="${order.realPayMoney}" format=".00" type="3"/>
									</b><s>(运费¥<sl:nformat num="${order.deliveryFeeMoney}" format=".00" type="1"/>)</s>
								</p>
							</div>
							<div class="nav_bottom">
								<p>
									<input type="hidden"  id="order_code" value="${order.orderCode}"/>
									<%--待审核状态（驳回、通过） --%>
									<c:if test="${order.orderStatus == '02' }">
										<a id="btn_reject" href="javascript:void(0)" class="btn1">驳回</a>
										<a id="btn_approve" href="javascript:void(0)" class="btn2">通过</a>
									</c:if>
								</p>
							</div>
						</div>
					</div>
				</dt>
			</c:forEach>
		</dl>
	</div>
</body>
</html>